define(['egis'], function (egis) {
    Window.deserializer = Window.deserializer || new egis.core.Deserializer();
    Window.container = Window.container || {};
    dsBridge.register('create_RestWSQSService', function (sourceId, url, http, authType, clientId, clientSecret, tokenUrl) {
        var restHttp = Window.container[http];
        var restGeoService = new egis.ews.RestWSQSService({
            url: url,
            http: restHttp,
            deserializer: Window.deserializer,
            clientId: clientId,
            authType: authType,
            clientSecret: clientSecret,
            tokenUrl: tokenUrl
        });
        Window.container[sourceId] = restGeoService;
    })

    dsBridge.registerAsyn('RestWSQSService_getCapabilities', function (sourceId, format, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        restWSQSService.getCapabilities(format).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    /*dsBridge.registerAsyn('RestWSQSService_find', function (sourceId, layerName, filter, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        filter = Window.deserializer.createJsInstance(JSON.parse(filter));
        restWSQSService.find(layerName, filter).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })



    dsBridge.registerAsyn('RestWSQSService_pageQuery', function (sourceId, layerName, filter, skip, size, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        filter = Window.deserializer.createJsInstance(JSON.parse(filter));
        restWSQSService.pageQuery(layerName, filter, skip, size).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_findById', function (sourceId, table, id, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        restWSQSService.findById(table, id).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_basicSearch', function (sourceId, basicSearchInput, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        basicSearchInput = Window.deserializer.createJsInstance(JSON.parse(basicSearchInput));
        restWSQSService.basicSearch(basicSearchInput).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_nearbySearch', function (sourceId, nearbySearchInput, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        nearbySearchInput = Window.deserializer.createJsInstance(JSON.parse(nearbySearchInput));
        restWSQSService.nearbySearch(nearbySearchInput).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_boundsSearch', function (sourceId, boundsSearchInput, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        boundsSearchInput = Window.deserializer.createJsInstance(JSON.parse(boundsSearchInput));
        restWSQSService.boundsSearch(boundsSearchInput).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_polygonSearch', function (sourceId, polygonSearchInput, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        polygonSearchInput = Window.deserializer.createJsInstance(JSON.parse(polygonSearchInput));
        restWSQSService.polygonSearch(polygonSearchInput).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
    */
    dsBridge.registerAsyn('RestWSQSService_findOne', function (sourceId, tableName, id, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        //wgcsInput = Window.deserializer.createJsInstance(JSON.parse(wgcsInput));
        restWSQSService.findOne(tableName, id).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })

    dsBridge.registerAsyn('RestWSQSService_find', function (sourceId, tableName, query, responseCallback) {
        var restWSQSService = Window.container[sourceId];
        query = Window.deserializer.createJsInstance(JSON.parse(query));
        restWSQSService.find(tableName, query).then(function (value) {
            responseCallback(JSON.stringify(value));
        })
    })
})